package com.zs4sdk.entity;

import com.common.library.entity.JSONResultEntity;
import com.common.library.util.Helper;

import org.json.JSONException;
import org.json.JSONObject;


/**
 * function: 注册返回JSON类
 *
 * @ author: aXiBa
 */
public class LoginJSONResultEntity extends JSONResultEntity {


    // 字段 名
    public static final String COLUMN_USERID = "userid";
    public static final String COLUMN_USERCODE = "usercode";
    public static final String COLUMN_USERDESC = "userdesc";
    public static final String COLUMN_TOKEN = "token";
    public static final String COLUMN_NICKNAME = "nickname";
    public static final String COLUMN_AVATARURL = "avatarurl";
    public static final String COLUMN_LOGINKEY = "loginkey";
    public static final String COLUMN_LOGINTYPE = "logintype";
    public static final String COLUMN_VERIFY = "verify";
    public static final String COLUMN_ISPWD = "ispwd";
    public static final String COLUMN_MOBILE = "mobile";
    public static final String COLUMN_LOGIN = "login_name";
    public static final String COLUMN_ISVERIFY = "isidverify";
    public static final String COLUMN_AGE = "age";

    // 1.6
    public static final String COLUMN_CLEARPASSWORDFLG = "clearPasswordFlg";

    // 1.7
    public static final String COLUMN_UPDATETIME = "updatetime";
    public static final String COLUMN_ISDELETE = "isdelete";
    public static final String COLUMN_ISAUTOASSIGN = "isAutoAssign";
    public static final String COLUMN_PASSWORD = "password";
    public static final String COLUMN_FLAGUPDATEPASSWORD = "flag_updatepassword";
    public static final String COLUMN_FLAGUPDATEEMAIL = "flag_updateemail";

    protected String userId;
    protected String usercode;  // 账号
    protected String userDesc;
    protected String token;
    protected String nickName;
    protected String avatarurl;
    protected String loginKey;
    protected String loginType;
    protected String verify; // 设备验证：是否最后一次用密码登录的设备
    protected String ispwd;//是否设置了密码
    protected String mobile;//手机号码
    protected String loginname;//登录账号
    protected String isverify;//账号是否认证
    protected String userAge = "0";//账号年龄

    // 1.6
    protected String clearPasswordFlg;   // 清空密码标识

    // 1.7
    protected long updatetime;
    protected String isdelete;
    protected String isAutoAssign;   // 是否为自动分配
    protected String password;       // 自动分配的密码
    protected String flag_updatePassword;   // 是否修改过密码
    protected String flag_updateEmail;   // 是否修改过邮箱


    /**
     * 构造方法
     */
    public LoginJSONResultEntity() {

    }

    /**
     * 构造方法
     *
     * @param json
     */
    public LoginJSONResultEntity(JSONObject json) {
        this.fromJSON(json);
    }

    /**
     * 构造方法
     *
     * @param jsonStr
     */
    public LoginJSONResultEntity(String jsonStr) {
        try {
            this.fromJSON(new JSONObject(jsonStr));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public JSONObject toJSON() {
        JSONObject result = super.toJSON();
        try {
            result.put(COLUMN_USERID, this.userId);
            result.put(COLUMN_USERCODE, this.usercode);
            result.put(COLUMN_USERDESC, this.userDesc);
            result.put(COLUMN_TOKEN, this.token);
            result.put(COLUMN_NICKNAME, this.nickName);
            result.put(COLUMN_AVATARURL, this.avatarurl);
            result.put(COLUMN_LOGINKEY, this.loginKey);
            result.put(COLUMN_LOGINTYPE, this.loginType);
            result.put(COLUMN_CLEARPASSWORDFLG, this.clearPasswordFlg);
            result.put(COLUMN_VERIFY, this.verify);
            result.put(COLUMN_ISPWD, this.ispwd);
            result.put(COLUMN_MOBILE,this.mobile);
            result.put(COLUMN_LOGIN,this.loginname);
            result.put(COLUMN_UPDATETIME, this.updatetime);
            result.put(COLUMN_ISDELETE, this.isdelete);
            result.put(COLUMN_ISAUTOASSIGN, this.isAutoAssign);
            result.put(COLUMN_PASSWORD, this.password);
            result.put(COLUMN_FLAGUPDATEPASSWORD, this.flag_updatePassword);
            result.put(COLUMN_FLAGUPDATEEMAIL, this.flag_updateEmail);
            result.put(COLUMN_ISVERIFY, this.isverify);
            result.put(COLUMN_AGE, this.userAge);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return result;
    }


    @Override
    public void fromJSON(JSONObject json) {
        super.fromJSON(json);
        if (Helper.isNotEmpty(json)) {
            this.userId = json.optString(COLUMN_USERID);
            this.usercode = json.optString(COLUMN_USERCODE);
            this.userDesc = json.optString(COLUMN_USERDESC);
            this.token = json.optString(COLUMN_TOKEN);
            this.nickName = json.optString(COLUMN_NICKNAME);
            this.avatarurl = json.optString(COLUMN_AVATARURL);
            this.loginKey = json.optString(COLUMN_LOGINKEY);
            this.loginType = json.optString(COLUMN_LOGINTYPE);
            this.clearPasswordFlg = json.optString(COLUMN_CLEARPASSWORDFLG);
            this.verify = json.optString(COLUMN_VERIFY);
            this.ispwd = json.optString(COLUMN_ISPWD);
            this.mobile = json.optString(COLUMN_MOBILE);
            this.loginname = json.optString(COLUMN_LOGIN);
            this.updatetime = json.optInt(COLUMN_UPDATETIME);
            this.isdelete = json.optString(COLUMN_ISDELETE);
            this.isAutoAssign = json.optString(COLUMN_ISAUTOASSIGN);
            this.password = json.optString(COLUMN_PASSWORD);
            this.flag_updatePassword = json.optString(COLUMN_FLAGUPDATEPASSWORD);
            this.flag_updateEmail = json.optString(COLUMN_FLAGUPDATEEMAIL);
            this.isverify = json.optString(COLUMN_ISVERIFY);
            this.userAge = json.optString(COLUMN_AGE);
        }
    }

    /**
     * 是否成功
     */
    public boolean isSuccess() {
        return this.getResult() == 1;
    }


    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserDesc() {
        return userDesc;
    }

    public void setUserDesc(String userDesc) {
        this.userDesc = userDesc;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getAvatarurl() {
        return avatarurl;
    }

    public void setAvatarurl(String avatarurl) {
        this.avatarurl = avatarurl;
    }

    public String getLoginKey() {
        return loginKey;
    }

    public void setLoginKey(String loginKey) {
        this.loginKey = loginKey;
    }

    public String getLoginType() {
        return loginType;
    }

    public void setLoginType(String loginType) {
        this.loginType = loginType;
    }

    public String getVerify() {
        return verify;
    }

    public void setVerify(String verify) {
        this.verify = verify;
    }

    public String getUsercode() {
        return usercode;
    }

    public String getClearPasswordFlg() {
        return clearPasswordFlg;
    }

    public void setClearPasswordFlg(String clearPasswordFlg) {
        this.clearPasswordFlg = clearPasswordFlg;
    }

    public void setUsercode(String usercode) {
        this.usercode = usercode;
    }

    @Override
    public String toString() {
        return toJSON().toString();
    }

    public long getUpdatetime() {
        return updatetime;
    }

    public void setUpdatetime(long updatetime) {
        this.updatetime = updatetime;
    }

    public String getIsdelete() {
        return isdelete;
    }

    public void setIsdelete(String isdelete) {
        this.isdelete = isdelete;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getIsAutoAssign() {
        return isAutoAssign;
    }

    public void setIsAutoAssign(String isAutoAssign) {
        this.isAutoAssign = isAutoAssign;
    }

    public String getFlag_updatePassword() {
        return flag_updatePassword;
    }

    public void setFlag_updatePassword(String flag_updatePassword) {
        this.flag_updatePassword = flag_updatePassword;
    }

    public String getFlag_updateEmail() {
        return flag_updateEmail;
    }

    public void setFlag_updateEmail(String flag_updateEmail) {
        this.flag_updateEmail = flag_updateEmail;
    }

    public String getIspwd() {
        return ispwd;
    }

    public void setIspwd(String ispwd) {
        this.ispwd = ispwd;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getLoginname() {
        return loginname;
    }

    public void setLoginname(String loginname) {
        this.loginname = loginname;
    }

    public boolean isVerify() {
        if(isverify.equals("1")) {
            return true;
        }
        else return false;
    }

    public void setIsverify(String isverify) {
        this.isverify = isverify;
    }

    public int getUserAge() {
        if (Helper.isNotNull(userAge)&&Helper.isNotEmpty(userAge)){
            int i = 0;
            try{
                i = Integer.parseInt(userAge);
            }catch (Exception e){
            }
            return i;
        }else {
            return 0;
        }
    }
}
